package com.bfsuol.yihang.customers.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bfsuol.core.redis.MybatisRedisCache;
import com.bfsuol.yihang.customers.entity.CustomerEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
//@CacheNamespace(implementation= MybatisRedisCache.class,eviction=MybatisRedisCache.class)
public interface CustomerMapper extends BaseMapper<CustomerEntity> {

    @Results(
            id="customerMapping",
            value={
                    @org.apache.ibatis.annotations.Result(column="customer_id",property="id"),
                    @org.apache.ibatis.annotations.Result(column="name",property="name"),
                    @org.apache.ibatis.annotations.Result(column="phone",property="phone"),
                    @org.apache.ibatis.annotations.Result(column="id_card",property="idCard"),
                    @org.apache.ibatis.annotations.Result(column="destination_car",property="destinationCar"),
                    @org.apache.ibatis.annotations.Result(column="remark",property="remark"),
                    @org.apache.ibatis.annotations.Result(column="create_userName",property="createUserName"),
                    @org.apache.ibatis.annotations.Result(column="update_userName",property="updateUserName"),
                    @org.apache.ibatis.annotations.Result(column="status",property="status"),
                    @org.apache.ibatis.annotations.Result(column="is_delete",property="isDelete"),
                    @org.apache.ibatis.annotations.Result(column="create_time",property="createTime"),
                    @org.apache.ibatis.annotations.Result(column="update_time",property="updateTime")
                }
    )
    @Select("<script>"+
                "select customer_id,name,phone,id_card,status,destination_car,remark," +
                "create_userName,update_userName,is_delete,create_time,update_time from t_buz_customer " +
                "where 1=1 " +
                "<if test='customerEntity.name != null and customerEntity.name.length()>0'>"+
                    "and name like ('%'+#{customerEntity.name}+'%' "+
                "</if>"+
                "<if test='customerEntity.phone != null and customerEntity.phone.length()>0'>"+
                    "and phone like ('%'+#{customerEntity.phone}+'%' "+
                "</if>"+
                "<if test='customerEntity.status != null'>"+
                    "and status = #{customerEntity.status} "+
                "</if>"+
                "and is_delete=0 "+
                "limit #{customerEntity.current}, #{customerEntity.size} "+
            "</script>")
    List<CustomerEntity> selectByLists(@Param("customerEntity") CustomerEntity customerEntity);

    @Select("<script>"+ "select count(*) from t_buz_customer " +
            "where 1=1 " +
            "<if test='customerEntity.name != null and customerEntity.name.length()>0'>"+
            "and name like ('%'+#{customerEntity.name}+'%' "+
            "</if>"+
            "<if test='customerEntity.phone != null and customerEntity.phone.length()>0'>"+
            "and phone like ('%'+#{customerEntity.phone}+'%' "+
            "</if>"+
            "<if test='customerEntity.status != null'>"+
            "and status = #{customerEntity.status} "+
            "</if>"+
            "and is_delete=0"+
            "</script>")
    Long selectCountBylists(@Param("customerEntity") CustomerEntity customerEntity);
}
